package eu.liquify.ui {
	import flash.display.Graphics;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.filters.BevelFilter;
	public class ProgressBar extends UIItem {
		
		private var _value:Number;
		
		private var display:Sprite = new Sprite();
		private var solid:Shape = new Shape();
		private var maxed:Boolean;
		
		public function ProgressBar() {
			addChild(display);
			display.addChild(solid);
			solid.filters = [new BevelFilter(3, 45, 0xFFFFFF, 0.2, 0x000000, 0.2, 4, 4, 1, 3)];
			value = 0;
		}
		
		public function get value():Number { return _value; }
		
		public function set value(v:Number):void {
			if (isNaN(v)) {
				v = 0;
				display.visible = false;
			} else {
				display.visible = true;
			}
			if (v > 1) {
				v = 1;
				maxed = true;
			} else {
				maxed = false;
				if (v < 0) v = 0;
			}
			_value = v;
			resize();
		}
		
		override public function resize():void {
			super.resize();
			redraw();
			height = 12;
		}
		
		private function redraw():void {
			var g:Graphics;
			
			g = display.graphics;
			g.clear();
			g.beginFill(0x939ADB);
			g.drawRoundRect(0, 0, width, 12, 8, 8);
			//g.lineStyle(1, 0x424FC1, 1, true);
			//g.beginFill(0xFFFFFF);
			g.beginFill(0xEDEEFA);
			g.drawRoundRect(1, 1, width-2, 10, 7, 7);
			
			g = solid.graphics;
			g.clear();
			g.beginFill(maxed ? 0xFDA666 : 0x96B3FE);
			g.drawRoundRect(2, 2, value*(width-4), 8, 5, 5);
		}
		
	}

}